(function(window, document) {
    angular
        .module('app')
        .factory('userSignFactory', userSignFactory);

    userSignFactory.$inject = ['$http', '$q'];

    function userSignFactory ($http, $q) {
        var service = {};
        var baseUrl = 'http://www.vipbanlv.com/api/';
        var _token; // 'FFFFFF7101010000000'
        var _machineType; // 0: iOS, 1: Android

        service.setToken = function(token) {
            _token = token;
        };

        service.setMachineType = function(machineType) {
            _machineType = machineType;
        };

        service.userSignPromise = function() {
            var deferred = $q.defer();
            $http({
                method: 'GET',
                url: baseUrl,
                params: {
                    m: 'user',
                    a: 'sign',
                    token: _token,
                    machine_type: _machineType
                }
            }).success(function(data) {
                deferred.resolve(data);
            }).error(function() {
                deferred.reject('There was an error.');
            });

            return deferred.promise;
        };

        // 返回service 对象
        return service;
    }
})(window, document);
